package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.ProductVisit;
import com.nbsaas.boot.product.api.domain.response.ProductVisitResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
/**
* 商品浏览记录-实体对象转化成响应对象
*/

public class ProductVisitResponseConvert  implements Converter<ProductVisitResponse,ProductVisit> {

    @Override
    public ProductVisitResponse convert(ProductVisit source) {
        ProductVisitResponse  result = new  ProductVisitResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getProduct()!=null){
                        result.setProduct(source.getProduct().getId());
                    }
                    if(source.getCreator()!=null){
                        result.setCreator(source.getCreator().getId());
                    }
                    if(source.getShop()!=null){
                        result.setShop(source.getShop().getId());
                    }

                    try {
                        if(source.getShop()!=null){
                            result.setShopName(source.getShop().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getProduct()!=null){
                    result.setProductLogo(source.getProduct().getLogo());
                    }

                    try {
                        if(source.getProduct()!=null){
                            result.setProductName(source.getProduct().getName());
                        }
                    } catch (Exception ignored) { }

        return result;
    }

}

